#include "derived.h"
#include <iostream>
#include <numeric>

namespace Derived {
    DerivedClass::DerivedClass() {
        std::cout << "DerivedClass constructor called" << std::endl;
    }
    
    void DerivedClass::addBase(const Base::BaseClass& base) {
        bases_.push_back(base);
        std::cout << "Added BaseClass to DerivedClass, total count: " << bases_.size() << std::endl;
    }
    
    std::vector<Base::BaseClass> DerivedClass::getBases() const {
        return bases_;
    }
    
    void DerivedClass::processAll() {
        std::cout << "Processing all BaseClass instances in DerivedClass:" << std::endl;
        for (size_t i = 0; i < bases_.size(); ++i) {
            std::cout << "  [" << i << "] Name: " << bases_[i].getName() 
                      << ", Value: " << bases_[i].getValue() << std::endl;
        }
    }
    
    int DerivedClass::getTotalValue() const {
        return std::accumulate(bases_.begin(), bases_.end(), 0,
            [](int sum, const Base::BaseClass& base) {
                return sum + base.getValue();
            });
    }
    
    void initializeDerived() {
        std::cout << "Derived library initialized" << std::endl;
        Base::initializeBase();  // 初始化依赖的基础库
    }
    
    void cleanupDerived() {
        std::cout << "Derived library cleaned up" << std::endl;
        Base::cleanupBase();  // 清理依赖的基础库
    }
}